'''
 pyqt5 GUI DEMO程序
'''
import sys

from PyQt5.QtWidgets import QApplication, QWidget, QFrame, QLabel, QLineEdit, QPushButton, QTextEdit




class PddRecordingApp(QWidget):
    def __init__(self):
        super().__init__()
        self.tip_text = None
        self.code_entry = None
        self.phone_entry = None
        self.initUI()

    def initUI(self):
        self.setWindowTitle("pdd直播流录制软件")
        self.resize(500, 500)

        # 上部分
        top_frame = QFrame(self)
        top_frame.setStyleSheet("")
        top_frame.setGeometry(0, 0, self.width(), self.height() * 0.1)

        phone_label = QLabel("手机号:", top_frame)
        phone_label.move(10, 10)

        self.phone_entry = QLineEdit(top_frame)
        self.phone_entry.setFixedWidth(120)
        self.phone_entry.move(60, 10)

        code_label = QLabel("验证码:", top_frame)
        code_label.move(200, 10)

        self.code_entry = QLineEdit(top_frame)
        self.code_entry.setFixedWidth(80)
        self.code_entry.move(260, 10)

        # 中部分
        middle_frame = QFrame(self)
        middle_frame.setStyleSheet("")
        middle_frame.setGeometry(0, self.height() * 0.1, self.width(), self.height() * 0.1)

        send_code_button = QPushButton("发送验证码", middle_frame)
        send_code_button.setFixedWidth(80)
        send_code_button.setFixedHeight(30)
        send_code_button.setStyleSheet("background-color: #FFFFFF;")
        send_code_button.clicked.connect(self.send_code_clicked)
        send_code_button.move(10, 10)

        login_button = QPushButton("登录", middle_frame)
        login_button.setFixedWidth(80)
        login_button.setFixedHeight(30)
        login_button.setStyleSheet("background-color: #FFFFFF;")
        login_button.clicked.connect(self.login_clicked)
        login_button.move(100, 10)

        record_button = QPushButton("开始录制", middle_frame)
        record_button.setFixedWidth(80)
        record_button.setFixedHeight(30)
        record_button.setStyleSheet("background-color: #FFFFFF;")
        record_button.clicked.connect(self.record_clicked)
        record_button.move(190, 10)

        config_button = QPushButton("更改配置文件", middle_frame)
        config_button.setFixedWidth(120)
        config_button.setFixedHeight(30)
        config_button.setStyleSheet("background-color: #FFFFFF;")
        config_button.clicked.connect(self.config_clicked)
        config_button.move(280, 10)

        # 下部分
        bottom_frame = QFrame(self)
        bottom_frame.setStyleSheet("")
        bottom_frame.setGeometry(0, self.height() * 0.2, self.width(), self.height() * 0.8)

        self.tip_text = QTextEdit(bottom_frame)
        self.tip_text.setReadOnly(True)
        self.tip_text.setText("这是要插入的文字，它会自动换行。\n")
        self.tip_text.setGeometry(10, 10, bottom_frame.width() - 20, bottom_frame.height() - 20)


    def send_code_clicked(self):
        self.tip_text.clear()
        # 获取手机号
        phone_number = self.phone_entry.text()
        if phone_number == "":
            self.tip_text.append("手机号不能为空")
            return
        self.tip_text.append("发送验证码至:"+phone_number)
        print("发送验证码")

    def login_clicked(self):
        print("登录")

    def record_clicked(self):
        print("开始录制")

    def config_clicked(self):
        print("更改配置文件")


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = PddRecordingApp()
    ex.show()
    sys.exit(app.exec_())